package com.dianjing.dianjing.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dianjing.dianjing.dto.output.PainterShowOutput;
import com.dianjing.dianjing.dto.output.WorksDetailOutput;
import com.dianjing.dianjing.entity.Painting;
import com.dianjing.dianjing.enums.CollectionTypeEnum;
import com.dianjing.dianjing.service.UserCollectionService;
import com.dianjing.dianjing.util.DataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  用户收藏
 * </p>
 *
 * @author owf
 * @since 2022-11-12
 */
@RestController
@RequestMapping("/user-collection")
@Api(tags = "用户收藏模块")
public class UserCollectionController {

    @Autowired
    private UserCollectionService userCollectionService;

    @PostMapping("/worksCollect/{userId}/{worksId}")
    @ApiOperation("用户收藏作品")
    public DataUtils worksCollect(@PathVariable("userId") Long userId,@PathVariable("worksId") Long worksId) {
        Boolean isCollectWorksSuccess = userCollectionService.userCollect(CollectionTypeEnum.TYPE_PAINTING.getType(), userId,worksId);
        if (isCollectWorksSuccess) {
            return DataUtils.ok("收藏作品成功");
        }else  {
            return DataUtils.error("收藏作品失败！");
        }
    }
    @PostMapping("/painterCollect/{userId}/{painterId}")
    @ApiOperation("用户收藏画师")
    public DataUtils painterCollect(@PathVariable("userId") Long userId,@PathVariable("painterId") Long painterId) {
        Boolean isCollectWorksSuccess = userCollectionService.userCollect(CollectionTypeEnum.TYPE_PAINTER.getType(), userId,painterId);
        if (isCollectWorksSuccess) {
            return DataUtils.ok("收藏画师成功");
        }else  {
            return DataUtils.error("收藏画师失败！");
        }
    }
    @GetMapping("/seeIsCollectdWorks/{userId}/{worksId}")
    @ApiOperation("查看用户是否已经收藏作品")
    public DataUtils seeIsCollectdWorks(@PathVariable("userId") Long userId,@PathVariable("worksId") Long worksId) {
        Boolean isCollectWorksSuccess = userCollectionService.isCollected(CollectionTypeEnum.TYPE_PAINTING.getType(),userId,worksId);
        return DataUtils.ok(isCollectWorksSuccess);
    }
    @GetMapping("/seeIsCollectdPainter/{userId}/{painterId}")
    @ApiOperation("查看用户是否已经收藏画师")
    public DataUtils seeIsCollectdPainter(@PathVariable("userId") Long userId,@PathVariable("painterId") Long worksId) {
        Boolean isCollectWorksSuccess = userCollectionService.isCollected(CollectionTypeEnum.TYPE_PAINTER.getType(), userId,worksId);
        return DataUtils.ok(isCollectWorksSuccess);
    }

    @GetMapping("/seeUserCollectPainter")
    @ApiOperation("查看用户收藏的指定画师")
    public DataUtils seeUserCollectPainter(@RequestParam("userId") Long userId,@RequestParam(value = "typeId",required = false) Integer typeId) {
        List<PainterShowOutput> painterShowOutputs =  userCollectionService.seeUserCollectPainter(userId,typeId);
        return DataUtils.ok(painterShowOutputs);
    }
    @GetMapping("/seeUserCollectWorks")
    @ApiOperation("获取用户收藏作品列表")
    public DataUtils seeUserCollectWorks(@RequestParam("userId") Long userId,@RequestParam(value = "typeId",required = false) Integer typeId) {
        List<Painting> paintings =  userCollectionService.seeUserCollectWorks(userId,typeId);
        return DataUtils.ok(paintings);
    }

    @PostMapping("/cancelCollectPainter/{userId}/{painterId}")
    @ApiOperation("用户取消收藏画师")
    public DataUtils cancelCollectPainter(@PathVariable("userId") Long userId,@PathVariable(value = "painterId") Integer painterId) {
        Boolean  isCancelSuccess =  userCollectionService.cancelCollect(CollectionTypeEnum.TYPE_PAINTER.getType(), userId,painterId);
        if(isCancelSuccess) {
            // 取消成功
            return DataUtils.ok();
        }else {
            // 取消失败
            return DataUtils.error("取消收藏画师失败");
        }
    }
    @PostMapping("/cancelCollectWorks/{userId}/{worksId}")
    @ApiOperation("用户取消收藏作品")
    public DataUtils cancelCollectWorks(@PathVariable("userId") Long userId,@PathVariable(value = "worksId") Integer worksId) {
        Boolean  isCancelSuccess =  userCollectionService.cancelCollect(CollectionTypeEnum.TYPE_PAINTING.getType(), userId,worksId);
        if(isCancelSuccess) {
            // 取消成功
            return DataUtils.ok();
        }else {
            // 取消失败
            return DataUtils.error("取消收藏作品失败");
        }
    }







}

